'use strict';

module.exports = app => {
  const { DataTypes, BIGINT, DATE } = app.Sequelize;

  const Stufile = app.model.define('stufile', {
    id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true },
    filename:{
        type:DataTypes.CHAR(60),
        allowNull:false
    },
    file_dir:{
        type:DataTypes.CHAR(120),
        allowNull:false,
    },
    progress:{
        type:DataTypes.INTEGER,
        allowNull:false,
    },
    canbedelete:{
      type:DataTypes.INTEGER,
      allowNull:false,
    }
   
  },{
      tableName:'t_student_file'
  });

  Stufile.associate = function(){
    app.model.Stufile.belongsTo(app.model.Student, {
        foreignKey: 'stu_id',
        as: 'student'
    })
  }
  Stufile.findbyNeedReviewArr = function () {
    return app.model.query(`
    select DATE_FORMAT(created_at,'%Y-%m-%d %T') as 'date',
GROUP_CONCAT(id) as 'gArray'
from t_student_file
where 
stu_id = 1 and progress IN (1,3) 
GROUP BY DATE_FORMAT(created_at,'%Y-%m-%d %T')
ORDER BY DATE_FORMAT(created_at,'%Y-%m-%d %T') DESC 
    `
    );
  }
  return Stufile;
};